import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'

//全局时间过滤器
Vue.filter('time', function (val) {
  //将时间转换为对象
  //获取到年月日时分秒，然后根据需求拼杰字符串
  var date = new Date(val)
  var Y = date.getFullYear();
  var M = date.getMonth();
  var D = date.getDate();
  var h = date.getHours();
  var f = date.getMinutes() + '';
  f = f.padStart(2, 0)
  var m = date.getSeconds() + '';
  m = m.padStart(2, 0)
  return `${Y}-${M}-${D} ${h}:${f}:${m}`
  //padStart(目标位数,"填充的字符") 不够目标位数  用填充的字符来填充

})

//导入全局样式表
import "./assets/css/global.css";

//引入字体图标库
import "./assets/fonts/iconfont.css"

//引入axios拦截器
import axios from "@/utils/request.js"
Vue.prototype.$axios = axios;

//ElementUI配置信息
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
Vue.use(ElementUI);

//echarts配置
import * as echarts from 'echarts';
Vue.prototype.$echarts = echarts;

//引入vant组件
import Vant from 'vant';
import 'vant/lib/index.css';
Vue.use(Vant);


//全局路由导航守卫
router.beforeEach((to, from, next) => {

  if (to.path === '/login') {
    return next()
  }
  let token = window.sessionStorage.getItem('lc_05B')//获取token
  if (!token) {
    return next('login')
  }
  next()
})

Vue.config.productionTip = false

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
